Skip to content

Parse decimal numbers from a CharSequence range - #13616

Draft
dougqh wants to merge 1 commit into
masterfrom
dougqh/charsequence-parsers
Draft

dougqh wants to merge 1 commit into
masterfrom
dougqh/charsequence-parsers

Conversation

@dougqh

@dougqh dougqh commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

What Does This Do

Adds range-based CharSequence overloads to LongStringUtils (an internal utility in dd-trace-api): parseUnsignedLong(CharSequence, start, end), parseLong(CharSequence, start, end) and parseInt(CharSequence, start, end). Each gives the same result, or NumberFormatException, as its String counterpart on the same chars. No callers yet.

Motivation

Part 1 of letting propagation parse header values in place. A Kafka consumer profile shows the header value Strings as the tracer's largest allocation site; several of them (x-datadog-trace-id, x-datadog-parent-id, x-datadog-sampling-priority) are parsed into numbers and never kept. Parsing them from a view of the record's bytes needs number parsers that take a CharSequence range, which Java 8 doesn't have (Long.parseLong(CharSequence, int, int, int) and its Integer counterpart are Java 9+).

The parts, each its own PR:

  1. This PR: CharSequence range parsers.
  2. A byte-backed ASCII view type, with a "valid only during the call; copy to keep" contract.
  3. The propagation contract: classifiers that accept a transient value, and a carrier cache that can hold views.
  4. Datadog extraction parsing ids and sampling priority from views.
  5. The Kafka carrier handing views for those headers.

Additional Notes

  • parseLong and parseInt follow the JDK's own algorithms for base 10 (optional +/-, Character.digit, accumulating negatively to detect overflow exactly), applied to the range.
  • parseUnsignedLong(CharSequence, ...) mirrors parseUnsignedLong(String): parseLong up to 18 chars, and the existing 19–20 digit unsigned path, now shared by both overloads (parseLongUnsignedDigits). The String overload's results are unchanged.
  • LongStringUtilsRangeTest compares each overload's outcome with its String counterpart (Long.parseLong, Integer.parseInt, parseUnsignedLong(String)) on the range of a larger StringBuilder: edge cases (empty, lone signs, +/- prefixes, spaces, letters, Unicode digits, every length boundary, signed and unsigned overflow), 50,000 random strings, and 20,000 random numbers of every magnitude.

🤖 Generated with Claude Code

Adds parseUnsignedLong / parseLong / parseInt overloads to LongStringUtils
that take the range [start, end) of a CharSequence and give the same result,
or NumberFormatException, as their String counterparts on the same chars
(Java 8 has no range-based CharSequence overloads of Long.parseLong /
Integer.parseInt). They let a header value be parsed in place, from a view,
without making a String first. parseUnsignedLong(String) now shares its
19-20 digit path with the range overload.

LongStringUtilsRangeTest compares outcomes with the String parsers on edge
cases (signs, Unicode digits, every length boundary, overflow) and on
random input.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougqh dougqh added tag: performance Performance related changes tag: no release notes Changes to exclude from release notes type: refactoring comp: api Tracer public API tag: ai generated Largely based on code generated by an AI or LLM labels Nov 21, 2026
@datadog-datadog-us1-prod

This comment has been minimized.

@dd-octo-sts

dd-octo-sts Bot commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 14.00 s 13.99 s [-0.5%; +0.8%] (no difference)
startup:insecure-bank:tracing:Agent 12.95 s 13.06 s [-1.5%; -0.3%] (maybe better)
startup:petclinic:appsec:Agent 17.20 s 17.07 s [+0.1%; +1.4%] (maybe worse)
startup:petclinic:iast:Agent 16.85 s 17.04 s [-2.0%; -0.3%] (maybe better)
startup:petclinic:profiling:Agent 16.15 s 16.27 s [-6.9%; +5.4%] (unstable)
startup:petclinic:sca:Agent 17.19 s 17.03 s [+0.1%; +1.7%] (maybe worse)
startup:petclinic:tracing:Agent 16.23 s 16.37 s [-1.6%; -0.0%] (maybe better)

Commit: d901668e · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: api Tracer public API tag: ai generated Largely based on code generated by an AI or LLM tag: no release notes Changes to exclude from release notes tag: performance Performance related changes type: refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant